package cn.semes.fallback;


import cn.semes.User;
import cn.semes.feignclient.UserService;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @BelongsProject: java0806-springcloud-netflix
 * @BelongsPackage: cn.itsource.fallback
 * @Author: shezhan
 * @CreateTime: 2022-12-19  14:31
 * @Description: TODO
 * @Version: 1.0
 */
// 别忘了交给spring
@Component
public class UserServiceFallbackFactory implements FallbackFactory<UserService> {

    /**
     * 工厂方法
     * @param throwable
     * @return
     */
    @Override
    public UserService create(Throwable throwable) {
        return new UserService() {
            // 这个方法就是你的getUser-feign接口的托底数据
            @Override
            public User getUser(Long id) {
                return new User(-1L, "opfenfeign熔断！", "网络错误");
            }
        };
    }
}
